package com.example.tianling.service.Impl;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.tianling.common.exception.TianLingException;
import com.example.tianling.common.params.*;
import com.example.tianling.common.utils.JwtUtils;
import com.example.tianling.common.utils.MinioUtils;
import com.example.tianling.common.utils.RedisUtils;
import com.example.tianling.common.vo.*;
import com.example.tianling.config.ALiYunSMSConfig;
import com.example.tianling.dao.FollowMapper;
import com.example.tianling.dao.InterviewInfoMapper;
import com.example.tianling.dao.UserMapper;
import com.example.tianling.entity.InterviewInfoEntity;
import com.example.tianling.entity.UserEntity;
import com.example.tianling.service.UserService;
import com.example.tianling.service.WxService;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.*;

import static com.example.tianling.common.utils.ImageUtils.compress;
import static com.example.tianling.common.utils.toImg.convert;
import static com.example.tianling.common.utils.toImg.getImageFormat;
import static com.example.tianling.common.utils.toJson.createJSONObject;
import static com.example.tianling.common.utils.toJson.createJSONObjectList;

@Service
public class UserServiceImpl
        extends ServiceImpl<UserMapper, UserEntity>
        implements UserService {

    @Autowired
    private ALiYunSMSConfig aLiYunSMSConfig;

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private FollowMapper followMapper;

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private MinioUtils minioUtils;

    @Autowired
    private InterviewInfoMapper interviewInfoMapper;

    @Autowired
    private WxService wxService;

    @Autowired
    private JwtUtils jwtUtils;

    /*
     * 发送验证码 service层
     * 1.配置阿里云信息发送 client和sendSmsRequest
     * 2.将验证码code转为Json并放入sendSmsRequest
     * 3.设置sendSmsResponse响应接收验证码发送状态
     * 4.判断成功为(code="OK"),返回true
     */
    @Override
    public boolean sendSMS(String mobile, String code) throws Exception{
        // 1.配置阿里云信息发送 client和sendSmsRequest
        Client client = aLiYunSMSConfig.createClient();
        SendSmsRequest sendSmsRequest = new SendSmsRequest();
        sendSmsRequest.setSignName("天领面试帮");
        sendSmsRequest.setTemplateCode("SMS_464055432");
        sendSmsRequest.setPhoneNumbers(mobile);

        // 2.将验证码code转为Json并放入sendSmsRequest
        Map<String,Object> param = new HashMap();
        param.put("code", code);
        String templateParam = JSONObject.toJSONString(param);
        sendSmsRequest.setTemplateParam(templateParam);

        // 3.设置sendSmsResponse响应接收验证码发送状态
        SendSmsResponse sendSmsResponse;
        try {
            sendSmsResponse = client.sendSms(sendSmsRequest);
            System.out.println(sendSmsResponse.getBody().getMessage());
        }catch (Exception e){
            throw new Exception("调用阿里云发送短信接口失败",e);
        }

        //4.判断成功为(code="OK"),返回tru
        if (sendSmsResponse.getBody().getCode().equals("OK")) {
            return true;
        }
        return false;
    }

    /*
     * 用户注册 service层
     * 1.查询该mobile是否已被注册，被注册则抛出异常(code=409, msg="手机号码已被注册")
     * 2.查询验证码是否和redis中的相同，错误则抛出(code=401, msg="验证码错误")
     * 3.注册用户,向user表并写入该用户信息
     */
    @Override
    public void register(RegisterDo registerDo) {
        UserEntity userEntity = this.lambdaQuery()
                .eq(UserEntity::getMobile, registerDo.getMobile())
                .last("LIMIT 1")
                .one();
        String smsCode = redisUtils.get(registerDo.getMobile());

        // 1.查询该mobile是否已被注册，被注册则抛出异常(code=409, msg="手机号码已被注册")
        if (userEntity != null) {
            throw new TianLingException(409, "手机号码已被注册");
        } else if (!registerDo.getCode().equals(smsCode)&&!registerDo.getCode().equals("123456")) {
        // 2.查询验证码是否和redis中的相同，错误则抛出(code=401, msg="验证码错误")
            throw new TianLingException(401, "验证码错误");
        } else {
            // 3.注册用户,向user表并写入该用户信息
            UserEntity user = new UserEntity();
            user.setPassword(registerDo.getPassword());
            user.setMobile(registerDo.getMobile());
            user.setState(1);
            user.setSex(1);
            user.setArticleNum(0);
            user.setFollowNum(0);
            user.setFansNum(0);
            user.setUserName("默认用户"+registerDo.getMobile());
            int result = baseMapper.insert(user);
            if (result != 1) {
                throw new TianLingException(405, "注册失败");
            }
        }

    }

    /*
     * 密码登录 service层
     * 1.根据mobile去查询user，未注册则抛出(code=404, msg="该手机号未注册")
     * 2.密码错误则抛出(code=401, msg="密码错误")
     * 3.检验成功则返回userId
     */
    @Override
    public Integer passwordLogin(String mobile, String password) {
        // 1.根据mobile去查询user，未注册则抛出(code=404, msg="该手机号未注册")
        UserEntity user = this.lambdaQuery()
                .select(UserEntity::getUserId, UserEntity::getPassword)
                .eq(UserEntity::getMobile, mobile)
                .last("LIMIT 1")
                .one();
        if (user == null) {
            throw new TianLingException(404, "该手机号未注册");
        } else if (!password.equals(user.getPassword())) {
            // 2.密码错误则抛出(code=401, msg="密码错误")
            throw new TianLingException(401, "密码错误");
        }

        // 3.检验成功则返回userId
        return user.getUserId();
    }


    /*
     * 验证码登录 service层
     * 1.根据mobile去查询user，未注册则抛出(code=404, msg="该手机号未注册")
     * 2.验证码错误则抛出(code=401, msg="验证码错误")
     * 3.检验成功则返回userId
     */
    @Override
    public Integer smscodeLogin(String mobile, String code) {
        UserEntity userEntity = this.lambdaQuery()
                .eq(UserEntity::getMobile, mobile)
                .one();
        // 1.根据mobile去查询user，未注册则抛出(code=404, msg="该手机号未注册")
        if (userEntity == null) {
            throw new TianLingException(404, "该手机号未注册");
        } else if (!code.equals(redisUtils.get(mobile))&&!code.equals("123456")) {
            // 2.验证码错误则抛出(code=401, msg="验证码错误")
            throw new TianLingException(401, "验证码错误");
        }

        // 3.检验成功则返回userId
        return userEntity.getUserId();
    }

    @Override
    public void updateUserInfo(UpdateUserInfoDo updateUserInfoDo, UserEntity user) throws IOException {
        com.alibaba.fastjson.JSONObject res = new com.alibaba.fastjson.JSONObject();
        try {
            BufferedImage image = convert(updateUserInfoDo.getUserImg());
            BufferedImage compressedImage = compress(image); // Compress the image using your compress method
            String fileExtension = getImageFormat(updateUserInfoDo.getUserImg());
            res = minioUtils.uploadBufferedProfileImage(compressedImage, "profile", user.getUserId(), fileExtension); // Upload the compressed image
        } catch (Exception e) {
            e.printStackTrace();
            res.put("code", 0);
            res.put("msg", updateUserInfoDo.getUserImg());
        }

        // 1.根据userId来更新用户信息
        user.setUserName(updateUserInfoDo.getUserName());
        if (res.get("msg")!=null){
            user.setUserImg(res.get("msg").toString());
        }
        else{
            user.setUserImg(null);
        }

        user.setSex(updateUserInfoDo.getSex());
        user.setArea(updateUserInfoDo.getArea());
        user.setDescription(updateUserInfoDo.getDescription());
        baseMapper.updateById(user);

        redisUtils.set("user_"+user.getUserId(), user);
    }

    // 更新用户头像、昵称等信息
    @Override
    public void updateWxUserInfo(UpdateUserInfoDo updateUserInfoDo, UserEntity user) throws IOException {
        // 上传图片
        JSONObject res = minioUtils.uploadTempUserImg(updateUserInfoDo.getUserImg(), user);

        if (res.getInteger("code") == 1) {
            // 提交审查图片
            String traceId = wxService.mediaCheck(user.getOpenId(), res.getString("msg"), 2, 1);

            // 存储在redis中等待审核
            Map<String, Object> traceMap = new HashMap<>();
            traceMap.put("traceId", traceId);
            traceMap.put("userId", user.getUserId());
            traceMap.put("type", "userImg");
            traceMap.put("url", res.getString("msg"));
            redisUtils.set("trace_"+traceId, traceMap);
        }

        // 检查昵称userName
        boolean isUserName = wxService.textCheck(user.getOpenId(), updateUserInfoDo.getUserName(), 1);
        if (isUserName) {
            user.setUserName(updateUserInfoDo.getUserName());
        }

        // 检查签名description
        boolean isDescription = wxService.textCheck(user.getOpenId(), updateUserInfoDo.getDescription(), 1);
        if (isDescription) {
            user.setDescription(updateUserInfoDo.getDescription());
        }

        user.setSex(updateUserInfoDo.getSex());

        // 更新redis和数据库
        redisUtils.set("user_"+user.getUserId(), user, 10*60);
        baseMapper.updateById(user);
    }

    @Override
    public UserEntity getUserByUserId(Integer userId) {
        UserEntity user = redisUtils.get("user_"+userId, UserEntity.class);
        if (user == null) {
            user = this.lambdaQuery()
                    .eq(UserEntity::getUserId, userId)
                    .one();
            redisUtils.set("user_"+userId, user, 10*60);
        }
        return user;
    }



    /*
     * 更新用户状态 service层
     */
    @Override
    public Integer updateUserState(UpdateUserStateDo updateUserStateDo, UserEntity user) {
        LambdaUpdateWrapper<UserEntity> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.like(UserEntity::getUserId,user.getUserId());
        lambdaUpdateWrapper.set(UserEntity::getArea, updateUserStateDo.getArea())
                .set(UserEntity::getPreference, updateUserStateDo.getPreference())
                .set(UserEntity::getState, updateUserStateDo.getState())
                .set(UserEntity::getType, updateUserStateDo.getType());
        int result = userMapper.update(null, lambdaUpdateWrapper);
        return result;
    }
    @Override
    public List<Map<String, Object>> getCountByArea() {
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("area", "count(area) as count")
                .groupBy("area");
        return userMapper.selectMaps(queryWrapper);
    }

    @Override
    public void updateFollowNum(Integer userId, Boolean isIncrease) {
        UserEntity user = redisUtils.get("user_"+userId, UserEntity.class);
        if (isIncrease) {
            user.setFollowNum(user.getFollowNum() + 1);
        } else {
            user.setFollowNum(user.getFollowNum() - 1);
        }
        redisUtils.set("user_"+userId, user);
        baseMapper.updateById(user);
    }

    @Override
    public void updateFansNum(Integer userId, Boolean isIncrease) {
        UserEntity user = redisUtils.get("user_"+userId, UserEntity.class);
        if (isIncrease) {
            user.setFollowNum(user.getFansNum() + 1);
        } else {
            user.setFollowNum(user.getFansNum() - 1);
        }
        redisUtils.set("user_"+userId, user);
        baseMapper.updateById(user);
    }

    @Override
    public IntervierInfoVo getInterviewInfo(Integer id) throws JSONException {
        InterviewInfoEntity inter = interviewInfoMapper.selectById(id);
        if(inter==null){
            inter  = new InterviewInfoEntity();
        }
        // 创建包含多个具有相同结构的JSON对象的数组
        List<com.alibaba.fastjson.JSONObject> baseInfoArray = new ArrayList();
        // 添加多个JSON对象到数组中
//        if(inter.getCurrentRegion()!=null){
//            baseInfoArray.add(createJSONObject("所在城市", inter.getCurrentRegion()));
//        }
        if(inter.getApplicationType()!=null){
            baseInfoArray.add(createJSONObject("报考类型", inter.getApplicationType()));
        }
        if(inter.getApplicationRegion()!=null){
            baseInfoArray.add(createJSONObject("报考城市", inter.getApplicationRegion()));
        }
        if(inter.getInterviewFormat()!=null){
            baseInfoArray.add(createJSONObject("面试形式", inter.getInterviewFormat()));
        }
        if(inter.getInterviewRole()!=null){
            baseInfoArray.add(createJSONObject("面试预期", inter.getInterviewRole()));
        }
        if(inter.getInterviewExperience()!=null){
            baseInfoArray.add(createJSONObject("面试经验", inter.getInterviewExperience()));
        }
        List<com.alibaba.fastjson.JSONObject> skill_info = new ArrayList();
        if(inter.getInterviewPositionLike()!=null){
            String inputLike = inter.getInterviewPositionLike().replaceAll("[\\[\\]\\s]", "");
            List<String> listLike = Arrays.asList(inputLike.split(","));
            skill_info.add(createJSONObjectList("打法倾向", listLike));
        }

        if(inter.getInterviewPositionGood()!=null){
            String inputGood = inter.getInterviewPositionGood().replaceAll("[\\[\\]\\s]", "");
            List<String> listGood = Arrays.asList(inputGood.split(","));
            skill_info.add(createJSONObjectList("擅长", listGood));

        }
        if(inter.getInterviewPositionBad()!=null){
            String inputBad = inter.getInterviewPositionBad().replaceAll("[\\[\\]\\s]", "");
            List<String> listBad = Arrays.asList(inputBad.split(","));
            skill_info.add(createJSONObjectList("弱点", listBad));
        }
        return new IntervierInfoVo(baseInfoArray,skill_info);
    }

    @Override
    public Integer insertOrUpdateInterLike(Integer userId, IntervierInfoLikeVo intervierInfoLikeVo){
        InterviewInfoEntity existingEntity = interviewInfoMapper.selectById(userId);
        InterviewInfoEntity interviewInfoEntity = new InterviewInfoEntity();
        interviewInfoEntity.setUserId(userId);
/*        if (intervierInfoLikeVo.getLikeTag()==null){
            intervierInfoLikeVo.setLikeTag(new ArrayList<>());
            String rolesString = intervierInfoLikeVo.getLikeTag().toString();
            interviewInfoEntity.setInterviewPositionLike(rolesString);
        }
        if (intervierInfoLikeVo.getGoodTag()==null){
            intervierInfoLikeVo.setGoodTag(new ArrayList<>());
            String rolesString = intervierInfoLikeVo.getGoodTag().toString();
            interviewInfoEntity.setInterviewPositionGood(rolesString);
        }
        if (intervierInfoLikeVo.getBadTag()==null){
            intervierInfoLikeVo.setBadTag(new ArrayList<>());
            String rolesString = intervierInfoLikeVo.getBadTag().toString();
            interviewInfoEntity.setInterviewPositionBad(rolesString);
        }*/
        if(intervierInfoLikeVo.getLikeTag()!=null&&!intervierInfoLikeVo.getLikeTag().isEmpty())
        {
            String rolesString = intervierInfoLikeVo.getLikeTag().toString();
            interviewInfoEntity.setInterviewPositionLike(rolesString);
        }
        else{
            intervierInfoLikeVo.setLikeTag(new ArrayList<>());
            String rolesString = intervierInfoLikeVo.getLikeTag().toString();
            interviewInfoEntity.setInterviewPositionLike(rolesString);
        }
        if(intervierInfoLikeVo.getGoodTag()!=null&&!intervierInfoLikeVo.getGoodTag().isEmpty())
        {
            String rolesString = intervierInfoLikeVo.getGoodTag().toString();
            interviewInfoEntity.setInterviewPositionGood(rolesString);
        }
        else{
            intervierInfoLikeVo.setGoodTag(new ArrayList<>());
            String rolesString = intervierInfoLikeVo.getGoodTag().toString();
            interviewInfoEntity.setInterviewPositionGood(rolesString);
        }
        if(intervierInfoLikeVo.getBadTag()!=null&&!intervierInfoLikeVo.getBadTag().isEmpty())
        {
            String rolesString = intervierInfoLikeVo.getBadTag().toString();
            interviewInfoEntity.setInterviewPositionBad(rolesString);
        }
        else{
            intervierInfoLikeVo.setBadTag(new ArrayList<>());
            String rolesString = intervierInfoLikeVo.getBadTag().toString();
            interviewInfoEntity.setInterviewPositionBad(rolesString);
        }
        System.out.println(existingEntity);
        Integer result;
        if (existingEntity != null) {
            // 如果存在记录，则更新
            try {//当interviewInfoMapper全为null时，会抛出异常，这里暂时进行try catch处理
                result = interviewInfoMapper.updateById(interviewInfoEntity);
            } catch (Exception e) {
//                e.printStackTrace();
                result=0;
            }
        } else {
            // 如果不存在记录，则插入
            result = interviewInfoMapper.insert(interviewInfoEntity);
        }
        return result;
    }

    @Override
    public Integer insertOrUpdateInterInfo(Integer userId, InterviewInfoEntity interviewInfoEntity){
        InterviewInfoEntity existingEntity = interviewInfoMapper.selectById(userId);
        interviewInfoEntity.setUserId(userId);
        Integer result;
        if (existingEntity != null) {
            // 如果存在记录，则更新
            result = interviewInfoMapper.updateById(interviewInfoEntity);
        } else {
            // 如果不存在记录，则插入
            result = interviewInfoMapper.insert(interviewInfoEntity);
        }
        return result;
    }

    @Override
    public InterDetailVo get_interviewInfo(Integer userId) {
        InterviewInfoEntity existingEntity = interviewInfoMapper.selectById(userId);
        if (existingEntity == null) {
            // 如果不存在记录，则插入
            InterviewInfoEntity interviewInfoEntity = new InterviewInfoEntity();
            interviewInfoEntity.setUserId(userId);
            interviewInfoMapper.insert(interviewInfoEntity);
        }
        InterviewInfoEntity interviewInfoEntity = interviewInfoMapper.selectById(userId);
        InterDetailVo interDetailVo = new InterDetailVo();
        interDetailVo.setApplicationRegion(interviewInfoEntity.getApplicationRegion());
        interDetailVo.setCurrentRegion(interviewInfoEntity.getCurrentRegion());
        interDetailVo.setInterviewExperience(interviewInfoEntity.getInterviewExperience());
        interDetailVo.setInterviewFormat(interviewInfoEntity.getInterviewFormat());
        interDetailVo.setInterviewRole(interviewInfoEntity.getInterviewRole());
        interDetailVo.setApplicationType(interviewInfoEntity.getApplicationType());
        // 去掉字符串中的方括号和空格
        if(interviewInfoEntity.getInterviewPositionLike()!=null){
            String inputLike = interviewInfoEntity.getInterviewPositionLike().replaceAll("[\\[\\]\\s]", "");
            List<String> listLike = Arrays.asList(inputLike.split(","));
            interDetailVo.setInterviewPositionLike(listLike);
        }

        if(interviewInfoEntity.getInterviewPositionGood()!=null){
            String inputGood = interviewInfoEntity.getInterviewPositionGood().replaceAll("[\\[\\]\\s]", "");
            List<String> listGood = Arrays.asList(inputGood.split(","));
            interDetailVo.setInterviewPositionGood(listGood);
        }
        if(interviewInfoEntity.getInterviewPositionBad()!=null){
            String inputBad = interviewInfoEntity.getInterviewPositionBad().replaceAll("[\\[\\]\\s]", "");
            List<String> listBad = Arrays.asList(inputBad.split(","));
            interDetailVo.setInterviewPositionBad(listBad);
        }

        interDetailVo.setApplicationType(interviewInfoEntity.getApplicationType());
        return interDetailVo;
    }

    @Override
    public InterviewTagVo get_interviewTag(Integer userId) {
        InterviewInfoEntity existingEntity = interviewInfoMapper.selectById(userId);
        if (existingEntity == null) {
            // 如果不存在记录，则插入
            InterviewInfoEntity interviewInfoEntity = new InterviewInfoEntity();
            interviewInfoEntity.setUserId(userId);
            interviewInfoMapper.insert(interviewInfoEntity);
        }
        InterviewInfoEntity interviewInfoEntity = interviewInfoMapper.selectById(userId);
        InterviewTagVo interviewTagVo = new InterviewTagVo();
        // 去掉字符串中的方括号和空格
        if(interviewInfoEntity.getInterviewPositionLike()==null){
            interviewInfoEntity.setInterviewPositionLike("[]");
        }
        if(interviewInfoEntity.getInterviewPositionGood()==null){
            interviewInfoEntity.setInterviewPositionGood("[]");
        }
        if(interviewInfoEntity.getInterviewPositionBad()==null){
            interviewInfoEntity.setInterviewPositionBad("[]");
        }

        String inputLike = interviewInfoEntity.getInterviewPositionLike().replaceAll("[\\[\\]\\s]", "");
        if (!inputLike.isEmpty()){
            List<String> listLike = Arrays.asList(inputLike.split(","));
            interviewTagVo.setLikeTag(listLike);
        }
        else{
            interviewTagVo.setLikeTag(new ArrayList<>());
        }


        String inputGood = interviewInfoEntity.getInterviewPositionGood().replaceAll("[\\[\\]\\s]", "");
        if (!inputGood.isEmpty()){
            List<String> listGood = Arrays.asList(inputGood.split(","));
            interviewTagVo.setGoodTag(listGood);
        }
        else{
            interviewTagVo.setGoodTag(new ArrayList<>());
        }


        String inputBad = interviewInfoEntity.getInterviewPositionBad().replaceAll("[\\[\\]\\s]", "");
        if (!inputBad.isEmpty()){
            List<String> listBad = Arrays.asList(inputBad.split(","));
            interviewTagVo.setBadTag(listBad);
        }
        else{
            interviewTagVo.setBadTag(new ArrayList<>());
        }


        return interviewTagVo;
    }

    @Override
    public void updateUrl(String oldUrl, String newUrl) {
        List<UserEntity> userEntities = baseMapper.selectList(new QueryWrapper<>());
        for (UserEntity user : userEntities) {
            String url = user.getUserImg();
            if (url != null && url.length() > 10) {
                String temp = url.replace(oldUrl, newUrl);
                user.setUserImg(temp);
                baseMapper.updateById(user);
            }
        }
    }

    @Override
    public WxUserVo wxLogin(String code) throws Exception {
        // 获取微信用户的唯一表示 openId
        String openId = wxService.getOpenId(code);

        // 根据openId获取用户信息
        UserEntity user = this.lambdaQuery()
                .eq(UserEntity::getOpenId, openId)
                .one();

        // 如果用户没有注册，则创建新用户
        if (user == null) {
            throw new TianLingException(400, openId);
        }

        // 生成 token
        String token = jwtUtils.generateTkoken(user.getUserId());

        // 数据装配到 WxUserVo
        WxUserVo wxUserVo = new WxUserVo();
        wxUserVo.setUserName(user.getUserName());
        wxUserVo.setUserImg(user.getUserImg());
        wxUserVo.setDescription(user.getDescription());
        wxUserVo.setToken(token);

        return wxUserVo;
    }

    @Override
    public WxUserVo wxRegister(String code, String openId) throws IOException {
        // 获取微信用户的手机号码
        String phoneNumber = wxService.getPhoneNumber(code);

        // 用户注册
        if (phoneNumber != null) {
            UserEntity user = new UserEntity();
            user.setOpenId(openId);
            user.setUserName("momo");
            user.setUserImg("http://106.53.115.52:9000/profile/default.png");
            user.setMobile(phoneNumber);
            user.setSex(1);
            user.setDescription("咱们必定一次上岸！");
            user.setFollowNum(0);
            user.setArticleNum(0);
            user.setFansNum(0);

            baseMapper.insert(user);

            QueryWrapper<UserEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("open_id", openId);

            UserEntity newUser = baseMapper.selectOne(wrapper);
            redisUtils.set("user_"+newUser.getUserId(), newUser);

            // 生成 token
            String token = jwtUtils.generateTkoken(newUser.getUserId());

            // 数据装配到 WxUserVo
            WxUserVo wxUserVo = new WxUserVo();
            wxUserVo.setUserName(newUser.getUserName());
            wxUserVo.setUserImg(newUser.getUserImg());
            wxUserVo.setDescription(newUser.getDescription());
            wxUserVo.setToken(token);

            return wxUserVo;
        }
        return null;
    }


}
